<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组去重的第一种方法</title>
</head>
<body>

</body>
</html>
<script>
    //1.构建一个新的数组存放结果

    //2.for循环中每次从原数组中取出一个元素，用这个元素循环与结果数组对比

    //3.若结果数组中没有该元素，则存到结果数组中
    Array.prototype.unique1 = function(){
        var res = [this[0]];
        for(var i = 1; i < this.length; i++){
            var repeat = false;
            for(var j = 0; j < res.length; j++){
                if(this[i] == res[j]){
                    repeat = true;
                    break;
                }
            }
            if(!repeat){
                res.push(this[i]);
            }
        }
        return res;
    };
    var arr = [1, 9, 7, 5, 3, 2, 2, 1, 1,4,5,7,9,2,4,6,7,8,];
    alert(arr.unique1());
</script>